home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk V.adf / ak / plutos.c < prev    next >
C/C++ Source or Header  |  1987-02-16  |  6KB  |  254 lines

  1. /* enkel deze includes nodig voor soundproductie */
  2. #include "hardware/custom.h"
  3. #include "stdio.h"
  4.  
  5. #include <exec/memory.h>
  6.  
  7. #include <exec/types.h>
  8. #include <intuition/intuition.h>
  9. #include <graphics/sprite.h>
  10.  
  11. struct Preferences MyPrefs;
  12. struct RastPort *rp;
  13. struct IntuitionBase *IntuitionBase;
  14. struct GfxBase *GfxBase;
  15. struct IntuiMessage *msg;
  16. unsigned short color[3];
  17. int red[3], green[3], blue[3];
  18.  
  19. #define NUM          6
  20. #define SPRHEIGHT       16
  21. #define WORDSPERSPR     (2 * SPRHEIGHT + 4)
  22.  
  23. struct NewWindow windef = {
  24.         0,0, 640, 200,
  25.         2, 3,
  26.     FOLLOWMOUSE|MOUSEBUTTONS,
  27.         REPORTMOUSE | WINDOWDRAG | ACTIVATE|SMART_REFRESH,
  28.         NULL, NULL,
  29.         (UBYTE *) "    BAMIGA SECTOR ONE PROUDLY PRESENTS  :  <<<<<<>  PLUTOS DEMO  <>>>>>>       ",
  30.         NULL, NULL, 0, 0, 0, 0,
  31.         WBENCHSCREEN
  32. };
  33.  
  34. struct SimpleSprite     spr[NUM];
  35. struct Window   *win;
  36. struct ViewPort *vp;
  37. UWORD           *sprbuf;
  38. UWORD           *sprites[NUM];
  39.  
  40. LONG filesize,s1,s2,per;
  41. char *filename;
  42. short *sndbuffer, *AllocMem();
  43.  
  44. main()
  45. {
  46. int i,j,xt,x;
  47.  
  48.  
  49.  
  50. /* aanroep van sound routine */
  51. per = 280;
  52. filename = "TAON_1";
  53. filesize = 42676;
  54. MakeSound();
  55.  
  56. openstuff ();
  57. ClearMenuStrip(win);
  58.  
  59.  
  60. color[1] = MyPrefs.color17;
  61. color[2] = MyPrefs.color18;
  62. color[3] = MyPrefs.color19;
  63.  
  64. for (i = 1; i <=3; i++)
  65. {
  66. red[i] = (color[i] >> 8) & 0x0F;
  67. green[i] = (color[i] >> 4) & 0x0F;
  68. blue[i] = color[i] & 0x0F;
  69. }
  70.  
  71. for (i = 17; i < 31; i = i + 4)
  72. {
  73. SetRGB4(vp, i, red[1], green[1], blue[1]);
  74. SetRGB4(vp, i+1, red[2], green[2], blue[2]);
  75. SetRGB4(vp, i+2, red[3], green[3], blue[3]);
  76. }
  77.  
  78.         setupsprites ();
  79.  
  80.         for (i=0; i<NUM; i++) {
  81.                 if (GetSprite (&spr[i], (long) i+1) < 0)
  82.                         die ("Sprite allocation failed.");
  83.                 spr[i].x = (win->MouseX + win->LeftEdge + MyPrefs.XOffset);
  84.                 spr[i].y = (win->MouseY + win->TopEdge + MyPrefs.YOffset - 1);
  85.                 spr[i].height = SPRHEIGHT;
  86.                 ChangeSprite (vp, &spr[i], sprites[i]);
  87.         }
  88.  
  89.  
  90. xt=0;
  91.  
  92.      for(;;) {
  93.  
  94.                 if (msg = GetMsg (win->UserPort))
  95.                 {
  96.                  ReplyMsg (msg);
  97.                  if (msg->Class == MOUSEBUTTONS)
  98.                  {
  99.                   while(msg=GetMsg(win->UserPort)) ReplyMsg(msg);
  100.                   custom.dmacon = 0x0003;
  101.                   closestuff();
  102.                   exit(1);
  103.                  }
  104.             }
  105.  
  106.                 for (i=NUM-1; i>=0; i--) 
  107.               {
  108.         spr[i].x = (win->MouseX + win->LeftEdge + MyPrefs.XOffset);
  109.         spr[i].y = (win->MouseY + win->TopEdge + MyPrefs.YOffset - 1);
  110.         ChangeSprite (vp, &spr[i], sprites[i]);
  111.         for(j=0;j<3;j++)WaitTOF();
  112.             }
  113.                 xt++;
  114.  
  115.                 if(xt==1)
  116.                 {
  117.                  SetWindowTitles(win,"    BAMIGA SECTOR ONE PROUDLY PRESENTS  :  <<<<<<>  PLUTOS DEMO  <>>>>>>       ",0);
  118.                 }
  119.                 if(xt==100)
  120.                 {
  121.                  SetWindowTitles(win,"        SPECIAL THANX TO LEDYSOFT FOR THE MARVELLOUS DIGITIZED ZOUND !!        ",0);
  122.                 } 
  123.                 if(xt==200) xt=0; 
  124.            }
  125.  
  126.  
  127. }
  128.  
  129. openstuff ()
  130. {
  131. IntuitionBase = OpenLibrary ("intuition.library", 0);
  132.  
  133.     /* Geez, guys, what if Intuition isn't here?  Who cares?  We're
  134.        probably all dead anyways, if this happens... */
  135.  
  136. GfxBase = OpenLibrary ("graphics.library", 0);
  137.  
  138.     /* Ya, sure, you've pulled the Graphics.Library ROM out, right? */
  139.  
  140.         if (!(win = OpenWindow (&windef)))
  141.                 die ("No memory for window");
  142.  
  143. GetPrefs(&MyPrefs, sizeof(struct Preferences));
  144.  
  145.         vp = ViewPortAddress (win);
  146.         rp = win.RPort;
  147.  
  148. }
  149.  
  150. closestuff ()
  151. {
  152.         int i;
  153.  
  154.  
  155.         if(sndbuffer)
  156.           FreeMem(sndbuffer,filesize);
  157.  
  158.         for (i=0; i<NUM; i++)
  159.                 if (spr[i].num)
  160.                         FreeSprite ((long) spr[i].num);
  161.  
  162.         if (sprbuf)
  163.                 FreeMem (sprbuf,2L * WORDSPERSPR * NUM);
  164.         if (win)
  165.                 CloseWindow (win);
  166.         if (GfxBase)
  167.                 CloseLibrary (GfxBase);
  168.         if (IntuitionBase)
  169.                 CloseLibrary (IntuitionBase);
  170. }
  171.  
  172. die (str)
  173. char *str;
  174. {
  175.         puts (str);
  176.         closestuff ();
  177.         exit (100);
  178. }
  179.  
  180. setupsprites ()
  181. {
  182. /* This is what I stole.  Boy, I hope it wasn't copyrighted... */
  183.  
  184.         UWORD *cw;  
  185.         UWORD *ballp; 
  186.         int frame, scan;
  187.  
  188.         if (!(sprbuf = AllocMem(2L * WORDSPERSPR * NUM, MEMF_CHIP)))
  189.                 die ("Can't allocate sprite buffer.");
  190.  
  191.         cw = sprbuf;    /* current position at top of buffer */
  192.         for (frame=0; frame<NUM; frame++) {
  193.                 sprites[frame] = cw;
  194.                 *cw++ = 0;              /* poscntl */
  195.                 *cw++ = 0;
  196.                 ballp = &MyPrefs.PointerMatrix[0]; 
  197.                 for (scan=0; scan<SPRHEIGHT; scan++) {
  198.                         *cw++ = *ballp++;
  199.                         *cw++ = *ballp++;
  200.                 }
  201.                 *cw++ = 0;      /* termination */
  202.                 *cw++ = 0;
  203.         }
  204. }
  205.  
  206.  
  207. MakeSound()
  208. {
  209. LoadSound();
  210. PlaySong();
  211. }  
  212.  
  213. LoadSound()
  214. {
  215. FILE *fopen(), *fp;
  216. SHORT *ptr;
  217. LONG i;
  218.  
  219. sndbuffer = AllocMem(filesize,MEMF_CHIP);
  220. ptr = sndbuffer;
  221.  
  222. custom . dmacon = 0x0003;
  223. fp = fopen(filename,"r");
  224. if (fp == NULL) return(0);
  225.  
  226. s1 = 0; s2 =filesize;
  227. for (i=0; i<s1; i++)
  228.     getc(fp);
  229.  
  230. for (i=s1/2; i<s2/2; i++)
  231.     {
  232.     *ptr++ = getc(fp)*256 + getc(fp);
  233.     }
  234.  
  235. fclose (fp);
  236. }
  237.  
  238. PlaySong()
  239. {
  240. custom . aud[0].ac_ptr = (UWORD *)sndbuffer;
  241. custom . aud[0].ac_len = s2/2-s1/2;
  242. custom . aud[0].ac_per = per;
  243. custom . aud[0].ac_vol = 64;
  244.  
  245. custom . aud[1].ac_ptr = (UWORD *)sndbuffer;
  246. custom . aud[1].ac_len = s2/2-s1/2;
  247. custom . aud[1].ac_per = per;
  248. custom . aud[1].ac_vol = 64;
  249.  
  250. custom . dmacon = 0x8203;
  251. }
  252.  
  253.  
  254.